package com.rain.shoppingscienceproj.ui.activity.shopping;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.rain.shoppingscienceproj.R;
import com.rain.shoppingscienceproj.ui.activity.BaseActivity;
import com.rain.shoppingscienceproj.ui.activity.search.SearchLocalityActivity;
import com.rain.shoppingscienceproj.ui.adapter.TypeShopAdapter;
import com.rain.shoppingscienceproj.ui.utile.TitleUtils;
import com.rain.shoppingscienceproj.utils.AppManager;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * - @Description:  商品
 * - @Author:
 * - @Time:
 */
public class ShoppingActivity extends BaseActivity {

    @BindView(R.id.message_iv)
    ImageView message_iv;
    @BindView(R.id.rc_data)
    RecyclerView mRecyelerView;
    String provinceId;
    String provincename;
    @BindView(R.id.tv_provincename)
    TextView tv_provincename;

    private TypeShopAdapter typeShopAdapter;

    @OnClick(R.id.et_finding_search)
    void search() {
        Intent intent = new Intent(ShoppingActivity.this, SearchLocalityActivity.class);
        intent.putExtra("type", 2);
        intent.putExtra("provinceId", provinceId);
        startActivity(intent);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shopping);
        AppManager.getAppManager().addActivity(this);
        ButterKnife.bind(this);
        TitleUtils.TitleView(this, "商品分类");
        provinceId = getIntent().getStringExtra("type");
        provincename = getIntent().getStringExtra("provincename");
        tv_provincename.setText("当前选省份：" + provincename);
        initView();
        initData();
        initListener();
    }

    private void initView() {
        message_iv.setVisibility(View.GONE);
    }

    private void initData() {
        mRecyelerView.setLayoutManager(new GridLayoutManager(this, 2));
        typeShopAdapter = new TypeShopAdapter(this);
        mRecyelerView.setAdapter(typeShopAdapter);
    }

    private void initListener() {
        typeShopAdapter.setItemClickListener(id ->
                startActivitys(GoodsListActivity.class, provinceId, id)
        );
    }

}
